import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'login',
      component: () => import('../views/login/login.vue')
    },
    {
      path: '/home',
      component: () => import('../views/home/index.vue')
    },
    {
      path: '/regirect',
      component: () => import('../views/login/regirect.vue')
    },

  ]
})

router.beforeEach((to, from, next) => {
  let token = localStorage.getItem('token')
  if (!token && to.name !== 'login') {
    alert('您必须登录')
    next({ path: "/" })
  } else {
    next()
  }
})

export default router
